import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/core/common/utils/palette_generator.dart';
import 'package:flutter_demo/ui/pages/bar/controller.dart';
import 'package:flutter_demo/ui/pages/bar/widgets/my_loading.dart';
import 'package:flutter_demo/ui/pages/comic/home/controller.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'dart:ui' as ui;

import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

class Renew extends StatefulWidget {
  const Renew({super.key});

  @override
  State<Renew> createState() => _RenewState();
}

class _RenewState extends State<Renew> {
  int _current = 0;
  CarouselController _carouselController = new CarouselController();
  final _listScroll = ScrollController();
  RefreshController _refreshController = RefreshController();
  final _homeController = Get.find<HomeController>();

  @override
  void initState() {
    print("initState 被调用");
    super.initState();
    _listScroll.addListener(() {
      _homeController.updateBar(_listScroll.position.pixels);
    });
  }

  @override
  void activate() {
    super.activate();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HomeController>(
        id: "barChange",
        builder: (control) {
          return Stack(children: [
            control.ifTransparent.value
                ? Container(
                    height: control.barHeight,
                    width: MediaQuery.of(context).size.width,
                    decoration: BoxDecoration(
                        color: Color.fromARGB(255, 230, 109, 109)),
                  )
                : const SizedBox.shrink(),
            Positioned(
                top: control.barHeight,
                height: MediaQuery.of(context).size.height,
                width: MediaQuery.of(context).size.width,
                child: SmartRefresher(
                    controller: _refreshController,
                    header: WaterDropHeader(
                      waterDropColor: Colors.green.shade700,
                      refresh: MyLoading(),
                      complete: Container(),
                      completeDuration: Duration.zero,
                    ),
                    onRefresh: () => _refreshController.refreshCompleted(),
                    child: ListView(controller: _listScroll, children: [
                      Container(
                        child: Text("abc"),
                        alignment: Alignment.center,
                        height: 500,
                      )
                    ])))
          ]);
        });
  }
}
